// pages/mycenter/mycenter.js
var api = require('../../config/api.js');
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    headList: [
      '/image/head1.png', '/image/head2.png', '/image/head3.png'
    ]
  },
  //获取数据
  getData() {
    let that = this;
    util.request(api.Center).then(function(res) {
      if (res.errno == 0) {
        wx.setStorageSync('users', res.data.user)
        that.setData({
          userInfo: res.data.user,
          orderInfo: res.data.order
        })
      } else {
        util.myToast(res.errmsg)
      }
    });
  },
  //猜你喜欢
  getHotData() {
    let that = this;
    util.request(api.HotGoods).then(function(res) {
      if (res.errno == 0) {
        that.setData({
          hotList: res.data
        })

      } else {
        util.myToast(res.errmsg)
      }
    });
  },
  //跳转个人信息
  onPersonInfo(e) {
    wx.navigateTo({
      url: '/pages/user-info/user-info',
    })
  },
  //帮助中心
  onHelpCenter(e){
    wx.navigateTo({
      url: '/pages/help-center/help-center',
    })
  },
  //跳转我的钱包
  onWallet(e) {
    wx.navigateTo({
      url: '/pages/my-wallet/my-wallet',
    })
  },
  //玩游戏
  onPlayGame() {
    wx.navigateTo({
      url: '/pages/game/game_index/game_index',
    })
  },

  //跳转收货地址
  onAddress(e) {
    wx.navigateTo({
      url: '/pages/address/address',
    })
  },

  // 跳转会员中心
  onVip(e) {
    wx.navigateTo({
      url: '/pages/vip_index/vip_index',
    })
  },

  // 跳轉优惠券列表
  onReceive(e) {
    wx.navigateTo({
      url: '/pages/coupon/coupon',
    })
  },

  // 跳转我的礼品卡
  onMycard(e) {
    wx.navigateTo({
      url: '/pages/card_list/card_list',
    })
  },
  //跳转到任务中心
  onTaskCenter(e) {
    wx.navigateTo({
      url: '/pages/integral/integral',
    })
  },
  //跳转到赠送记录
  onSendRecord(e){
    wx.navigateTo({
      url: '/pages/send-record/send-record',
    })
  },

  //跳转待付款
  onDFK(e) {
    util.toClass('/pages/myorder/myorder', {
      status: 1
    })
  },
  //跳转待发货
  onDFH(e) {
    util.toClass('/pages/myorder/myorder', {
      status: 2
    })
  },
  //跳转待收货
  onDSH(e) {
    util.toClass('/pages/myorder/myorder', {
      status: 3
    })
  },
  //跳转我的订单
  onLookOrder(e) {
    util.toClass('/pages/myorder/myorder', {
      status: '0'
    })
  },
  //跳转评价订单
  onLookEvaluate(e) {
    wx.navigateTo({
      url: '/pages/my-evaluate/my-evaluate',
    })
  },
  //跳转退款售后订单
  onLookRefund(e) {
    wx.navigateTo({
      url: '/pages/my-refund/my-refund',
    })
  },

  //跳转收货地址
  onAddress(e) {
    wx.navigateTo({
      url: '/pages/address/address',
    })
  },
  //猜你喜欢详情
  onLikeItemClick(e) {
    var id = e.currentTarget.dataset.id;
    util.toClass('/pages/details/details', {
      goodsid: id
    })
  },
  //快速加入购物车
  onAddShop(e) {
    var id = e.currentTarget.dataset.id;
    this.getAddCar(id);
  },
  //加入购物车
  getAddCar(goodsId) {
    let that = this;
    util.request(api.CartAdd, {
      number: 1,
      goodsId: goodsId
    }, 'post').then(function(res) {
      if (res.errno == 0) {
        wx.showToast({
          title: '加入购物车！',
        })
      } else {
        util.myToast(res.errmsg)
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getHotData();
    //分享到朋友圈
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    return {
      title: "傣王稻勐海香米，一键领取优惠",
      path: '/pages/index/index?userid=' + wx.getStorageSync("userid"),
      imageUrl: 'https://zebra-1258707023.cos.ap-chengdu.myqcloud.com/yndwd/share-img.jpg'
    }
  }
})